package com.jie.controller;

import com.jie.domain.User;
import com.jie.service.UserServcie;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @author jie
 * @date 2019/7/31 -18:45
 */
@RestController
public class HelloController {

    @Autowired
    UserServcie userServcie;

    private final Logger logger = Logger.getLogger(getClass());
    @Value("${server.port}")
    String port;

    @GetMapping("hello")
    public String hello() {
        logger.info("/hello, host:" + port);
        return "hello, host:" + port;
    }


    @GetMapping("users/{id}")
    public User getUsersByUserId(@PathVariable Integer id) {
        return userServcie.getUsersByUserId(id);
    }

    @GetMapping("hello2")
    public String hello2() {
        logger.info("/hello, host:" + port);
        return "hello, host:" + port;
    }

    @GetMapping("/hello1")
    public String hello(@RequestParam("name") String name) {
        return "hello" + name;
    }

    @GetMapping("/hello3")
    public User info(@RequestHeader("name") String name, @RequestHeader("age") Integer age) {
        User user = new User();
        user.setName(name);
        user.setAge(age);
        return user;
    }
}
